var default_data = {
    content: "",
    duration: 2,
    //显示时间，默认2秒
    show: false
};

let timer = null;

Component({
    options: {},
    externalClasses: [ "m-class" ],
    data: {
        ...default_data
    },
    methods: {
        show(options) {
            const {duration: duration = 2} = options;
            //获取自定义显示时长
                        this.setData({
                ...options,
                show: true
            });
            const secondToMMsecond = duration * 1e3;
            //秒转毫秒
                        if (timer) {
                clearTimeout(timer);
                //有计时器，清除计时器
                        } else {
                timer = setTimeout(() => {
                    this.hide(options);
                }, secondToMMsecond);
            }
        },
        hide(options) {
            this.setData({
                show: false
            });
        }
    }
});